package labox.innovation.gameserver.network.clientpackets;

import labox.innovation.gameserver.model.ConsignmentCache;
import labox.innovation.gameserver.model.ConsignmentManager;
import labox.innovation.gameserver.model.actor.instance.FuzePcInstance;
import labox.innovation.gameserver.network.serverpackets.ConItemHighPacket;

/**
 * @author ljsh
 * @date 2010-5-4
 * @version 1.0
 * @description  请求翻页查找结果
 */
public class RequestPageTurning extends L2GameClientPacket {
	private static final String _C_REQUESTPAGETURING = "[C]  RequestPageTurning";
	private int _turnModel;
	@Override
	public String getType() {
		return _C_REQUESTPAGETURING;
	}

	@Override
	protected void readImpl() {
		_turnModel=readByte();
	}

	@Override
	protected void runImpl() {
		FuzePcInstance active = getClient().getActiveChar();
		if (active == null)
			return;
		ConsignmentCache cache=ConsignmentManager.getSearcheCache(active.getObjectId());
		int currentpage=cache.getCurrentPage();
		if(_turnModel==ConsignmentManager.PREVIOUSPAGE){
			if(currentpage<=1){
				active.sendMessage("当前是最前页");
				return;
			}
			cache.setLastPage(false);
			cache.setCurrentPage(currentpage-1);
			active.sendPacket(new ConItemHighPacket(active,cache.getSearchType(),cache.getSearchCondition()));
		}else if(_turnModel==ConsignmentManager.NEXTPAGE){
			if(cache.isLastPage()){
				active.sendMessage("当前是最后一页");
				return;
			}
			cache.setCurrentPage(currentpage+1);
			active.sendPacket(new ConItemHighPacket(active,cache.getSearchType(),cache.getSearchCondition()));
		}else{
			active.sendMessage("非法操作");
		}
		
		
	}

}
